package com.heima.repository.impl;

import com.heima.pojo.Dept;
import com.heima.repository.DeptRepository;
import org.springframework.stereotype.Repository;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

@Repository
public class DeptRepoImpl implements DeptRepository {
    private static Map<Integer,Dept> deptMap;
    static{
        deptMap = new HashMap<>();
        deptMap.put(1,new Dept(1,"张三",23));
        deptMap.put(2,new Dept(2,"张三",25));
        deptMap.put(3,new Dept(3,"张三",27));
    }
    @Override
    public Collection<Dept> findAll() {
        return deptMap.values();
    }

    @Override
    public Dept findById(Integer id) {
        return deptMap.get(id);
    }

    @Override
    public void save(Dept dept) {
        deptMap.put(dept.getId(),dept);
    }

    @Override
    public void deleteById(Integer id) {
        deptMap.remove(id);
    }
}
